package com.yanqu.road.server.cmd.clinic;

import com.yanqu.road.pb.clinic.ClinicProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.config.ClinicMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/3/8 17:51
 */
@Cmd(code = GameProtocol.S_CLINIC_VISIT_OTHER_CLINIC, desc = "拜访其他玩家医馆")
public class VisitOtherClinicCmd extends AbstractCommand {
    private long otherPlayerId;
    private long otherPlayerServerId;
    private ClinicProto.VisitOtherClinicReqMsg msg;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        msg = ClinicProto.VisitOtherClinicReqMsg.parseFrom(packet.getBytes());
        otherPlayerId = msg.getUserId();
        otherPlayerServerId = msg.getServerId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (otherPlayerServerId == GameServer.getInstance().getServerId()) {
            //本服拜访
            ClinicProto.VisitOtherClinicRespMsg.Builder respMsg = ClinicMgr.visitClinic(otherPlayerId);
            player.sendPacket(ClientProtocol.U_CLINIC_VISIT_OTHER_CLINIC, respMsg);
        } else {
            //跨服拜访
            player.sendPacket(CrossProtocol.C_CROSS_VISIT_PLAYER_CLINIC, msg.toBuilder());
        }
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
